<template>
  <div class="page">
    <template v-if="AppleAssembleList.length">
    <div class="weui-cells" v-for="(item,index) in AppleAssembleList" :key="index">
      <a class="weui-cell" @click="goDetail(item)">
        <div class="weui-cell__hd ac_pic">
          <img :src="item.actv_cover_img" mode="widthFix">
          <div class="ac_type" >
            <span style="display: inline-block;height: 100%;writing-mode: vertical-lr;">{{item.typeName}}</span>
          </div>
        </div>
        <div class="weui-cell__bd">
          <div class="ac_title">{{item.actv_content}}</div>
          <div class="s_info">
            <div><span>活动时间：</span>{{item.time_desc}}</div>
            <div><span>使用条件：</span>{{item.ConditionData}}</div>
            <div><span>活动规则：</span><span v-html="item.rule_content"></span></div>
          </div>
        </div>
      </a>
    </div>
    </template>
    <div style="text-align:center;margin-top:0.9em;" v-if="!AppleAssembleList.length">
      暂无数据
    </div>
  </div>
</template>

<script>
import card from '@/components/card'
  import * as appId from "@/utils/util"
  import * as condition from "@/utils/options"
export default {
  data () {
    return {
      current: 0,
      AppleAssembleList:[],
      pageNo:1,
      pageSize:10,
      result:[],
      ConditionData:"",
      type:[{
        id:'1',
        type:'满减'
      },{
        id:'2',
        type:'送券'
      },{
        id:'3',
        type:'红包'
      },{
        id:'4',
        type:'积分'
      },{
        id:'5',
        type:'特价'
      },{
        id:'6',
        type:'立减'
      },{
        id:'99',
        type:'抽奖'
      },{
        id:'20',
        type:'拼团'
      },{
        id:'19',
        type:'报名'
      },{
        id:'66',
        type:'新会员奖励'
      }]
    }
  },
  onShow(){
    this.pageNo=1;
    wx.setNavigationBarTitle({
      title: "活动列表"
    })
     this.getAppleAssembleListFun()
  },

  components: {
    card
  },
   onPullDownRefresh(){
     console.log('down')
      if(this.result.length){
     this.pageNo++;
    }
     this.getAppleAssembleListFun()

  },
  onReachBottom () {
    wx.showNavigationBarLoading()
    console.log('pull')
    if(this.result.length){
     this.pageNo++;
    }
    this.getAppleAssembleListFun()
    // wx.stopPullDownRefresh()
   },
  methods: {
    getTypeName(id){
      console.log(id)
      let arr=this.type.filter((item)=>{
        return item.id==id;
      })[0]||{}
      console.log(arr.type)
      return arr.type;
    },
    goDetail(row){
      let url="/pages/activitydetail/main?id="+row.id;
          // wx.setStorageSync('AppleAssembleList', JSON.stringify(row))
      wx.navigateTo({ url })
    },
    changeCondition(val){
      var str="";
      condition.condition.forEach((a,i)=>{
        if(a.value==val){
          str=a.label;
        }
      })
      return str;
    },
    getAppleAssembleListFun(){
      let that=this;
         this.$http.request({
            method: "post",
            url: "/v1.0/appletHome/appletAssembleList",
            body: {
              "appid": appId.appId,
              "pageNo": that.pageNo,
              "pageSize": that.pageSize,
              status:'1'
            }
          }).then((data)=>{
            if(data.code==0){
              this.result=data.result;
               if (that.pageNo > 1) {
              that.AppleAssembleList.push(...data.result)
              }else{
                that.AppleAssembleList=data.result;
              }
              that.AppleAssembleList.forEach((a,i)=>{
                a.typeName=this.getTypeName(a.type);
                console.log(that.changeCondition(a.receiving_condition))
                a.ConditionData=that.changeCondition(a.receiving_condition)
              })
              console.log( that.AppleAssembleList)

               if(!data.length){
               wx.stopPullDownRefresh();
              //  wx.showToast({
              //   title: '暂无更多数据',
              //   icon: 'none',
              //   duration: 2000
              // })
            }
            }else{
                wx.showToast({
                title: `${data.message}`,
                icon: 'none',
                duration: 2000
              })
            }
          })
    },
    bindViewTap () {
      const url = '../logs/main'
      if (mpvuePlatform === 'wx') {
        mpvue.switchTab({ url })
      } else {
        mpvue.navigateTo({ url })
      }
    }
  },

  created () {
    // let app = getApp()
  }
}
</script>

<style scoped>
.ac_pic{
  position: relative;
}
.ac_pic img{
  width: 6em;
  height: 6em;
  border-radius: 0.3em;
  margin-right: 0.6em;
}
.ac_pic .ac_type{
  position: absolute;
  left: 0.5em;
  top:0px;
  background: #FF787E;
  width: 1.6em;
  height: 2em;
  color: #fff;
  text-align:center;
  line-height: 0.8em;
}
.ac_pic .ac_type span{
  font-size: 0.8em;
  padding-top: 0.2em;
}
.ac_pic .ac_type::after{
  content: '';
  position: absolute;
  bottom: -0.4em;
  left: 0px;
  right: 0px;
  width:0;
	height:0;
	border-right:0.8em solid transparent;
	border-left:0.8em solid transparent;
	border-top:0.4em solid #FF787E;
}
.s_info div{
  font-size: 0.8em;
  color: #333;
  line-height: 1.8em;
}
.s_info div span{
  color: #999;
}
</style>
